import request from "@/utils/request";
import { getToken, getUserId, getSiteId } from "@/utils/auth";

// 数据统计
export function statictisApi({ AccessToken, SiteId, UserId }) {
  return request({
    url: "/StatisticsV2/GetFactoryStatistics",
    method: "get",
    params: {
      AccessToken,
      SiteId,
      UserId,
    },
  });
}

// 工序统计
export function trackApi({ AccessToken, SiteId, UserId, GroupBy }) {
  return request({
    url: "/TrackStatisticsV2/GetTrackStatistics",
    method: "get",
    params: {
      GroupBy,
      AccessToken,
      SiteId,
      UserId,
      BeginDate: "2024-08-01",
      EndDate: "2024-08-31",
    },
  });
}

// 超时统计（flag=2），异常统计（flag=3）
export function flagApi({ Flag }) {
  return request({
    url: "/ProduceStatisticsV2/GetProduceStatistics",
    method: "get",
    params: {
      Flag,
      AccessToken: getToken(),
      SiteId: getSiteId(),
      BeginDate: "2024-08-01",
      EndDate: "2024-08-31",
    },
  });
}

// 销售量统计（type=1，按月；type=2，按日）
export function saleStatApi({ Type }) {
  return request({
    url: "/SaleStatisticsV2/GetSaleStatistics",
    method: "get",
    params: {
      AccessToken: getToken(),
      SiteId: getSiteId(),
      UserId: getUserId(),
      Type,
    },
  });
}

// 接单员列表
export function orderTakersApi(data) {
  return request({
    url: "/OrderClerkV2/GetOrderClerkStatistics",
    method: "get",
    params: {
      AccessToken: getToken(),
      SiteId: getSiteId(),
      BeginDate: data?.BeginDate || "2024-08-01",
    },
  });
}

// 业务员列表
export function salesmenApi(data) {
  return request({
    url: "/SalesmanV2/GetSalesmanStatistics",
    method: "get",
    params: {
      AccessToken: getToken(),
      SiteId: getSiteId(),
      BeginDate: data?.BeginDate || "2024-08-01",
    },
  });
}
// 客户统计
export function customerStatApi(data = {}) {
  return request({
    url: "/CustomerV2/GetCustomerStatistics",
    method: "get",
    params: {
      AccessToken: getToken(),
      SiteId: getSiteId(),
      MonthType: data.MonthType !== undefined ? data.MonthType : 0,
      KeyStr: "",
      PageIndex: data.pageIndex !== undefined ? data.pageIndex : 1,
    },
  });
}

// 客户预警
export function customerAlarmApi(data = {}) {
  return request({
    url: "/WarningV2/GetCustomerWarning",
    method: "get",
    params: {
      AccessToken: getToken(),
      SiteId: getSiteId(),
      MonthType: data.MonthType !== undefined ? data.MonthType : 0,
      KeyStr: "",
      PageIndex: data.pageIndex !== undefined ? data.pageIndex : 1,
    },
  });
}
